package com.application;

import android.annotation.SuppressLint;
import android.os.Bundle;
import android.webkit.WebResourceRequest;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;

import androidx.appcompat.app.AppCompatActivity;
import androidx.databinding.DataBindingUtil;

import com.alibaba.android.arouter.facade.annotation.Route;
import com.application.databinding.ActivityWebWeChatBinding;
import com.application.util.ARouterConstants;

@Route(path = ARouterConstants.ACTIVITY_URL_WEB_WECHAT)
public class WebWeChatActivity extends AppCompatActivity {

    private ActivityWebWeChatBinding binding;
    private WebView webView;

    @SuppressLint("SetJavaScriptEnabled")
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        binding= DataBindingUtil.setContentView(this,R.layout.activity_web_we_chat);
        binding.setActivity(this);
        webView=binding.webWechat;
        String url=getIntent().getStringExtra("url");

        WebSettings webSettings=webView.getSettings();
        webSettings.setJavaScriptEnabled(true);
        webSettings.setDomStorageEnabled(true);

        webView.setWebViewClient(new WebViewClient(){
            @Override
            public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request) {
                view.loadUrl(url);
                return true;
            }
        });
        if (url != null) {
            webView.loadUrl(url);
        }

    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        if (webView!=null){
            webView.destroy();
            webView=null;
        }
        binding=null;
    }
}